package com.example.tianxi.yuexiuhhpatient;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.webkit.WebView;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.example.tianxi.yuexiuhhpatient.Adapter.HistoryAdapter;
import com.example.tianxi.yuexiuhhpatient.Adapter.RecommandDoctorAdapter;
import com.example.tianxi.yuexiuhhpatient.Entity.HistoryEntity;
import com.example.tianxi.yuexiuhhpatient.Entity.RecommandDoctor;

import java.util.ArrayList;
import java.util.List;


public class RecommendDoctorActivity extends Activity implements AbsListView.OnItemClickListener{


    private TextView back;
    private TextView title;
    private  TextView action;

    private List<RecommandDoctor> lists;

    private ListAdapter mAdapter;

    private ListView mListView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_recommend_doctor);
        initView();

        initData();
    }

    public void initView(){
        back = (TextView)findViewById(R.id.back);
        title = (TextView)findViewById(R.id.title);
        action = (TextView)findViewById(R.id.action);


        back.setText("返回");
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        title.setText("推荐医生");
        action.setText("");

    }

    public void initData(){
        lists = new ArrayList<RecommandDoctor>();

        lists.add(new RecommandDoctor("王小波","骨科","住院医师","越秀区第一人民医院","肚子疼,肠炎，外加轻微的胃炎，小肠气"));
        lists.add(new RecommandDoctor("韩寒","骨科","住院医师","越秀区第一人民医院","肚子疼,肠炎，外加轻微的胃炎，小肠气"));
        lists.add(new RecommandDoctor("冯唐","骨科","住院医师","越秀区第一人民医院","肚子疼,肠炎，外加轻微的胃炎，小肠气"));
        lists.add(new RecommandDoctor("莫言","骨科","住院医师","越秀区第一人民医院","肚子疼,肠炎，外加轻微的胃炎，小肠气"));
        lists.add(new RecommandDoctor("村上春树","骨科","住院医师","越秀区第一人民医院","肚子疼,肠炎，外加轻微的胃炎，小肠气"));
        lists.add(new RecommandDoctor("安妮宝贝","骨科","住院医师","越秀区第一人民医院","肚子疼,肠炎，外加轻微的胃炎，小肠气"));
        lists.add(new RecommandDoctor("路金波","骨科","住院医师","越秀区第一人民医院","肚子疼,肠炎，外加轻微的胃炎，小肠气"));
        lists.add(new RecommandDoctor("王朔","骨科","住院医师","越秀区第一人民医院","肚子疼,肠炎，外加轻微的胃炎，小肠气"));
        lists.add(new RecommandDoctor("王安忆","骨科","住院医师","越秀区第一人民医院","肚子疼,肠炎，外加轻微的胃炎，小肠气"));
        lists.add(new RecommandDoctor("村上春树","骨科","住院医师","越秀区第一人民医院","肚子疼,肠炎，外加轻微的胃炎，小肠气"));
        lists.add(new RecommandDoctor("安妮宝贝","骨科","住院医师","越秀区第一人民医院","肚子疼,肠炎，外加轻微的胃炎，小肠气"));
        lists.add(new RecommandDoctor("路金波","骨科","住院医师","越秀区第一人民医院","肚子疼,肠炎，外加轻微的胃炎，小肠气"));
        lists.add(new RecommandDoctor("王朔","骨科","住院医师","越秀区第一人民医院","肚子疼,肠炎，外加轻微的胃炎，小肠气"));
        lists.add(new RecommandDoctor("王安忆","骨科","住院医师","越秀区第一人民医院","肚子疼,肠炎，外加轻微的胃炎，小肠气"));

        //创建自己的适配器
        mAdapter = new RecommandDoctorAdapter(this,lists);

        // Set the adapter
        mListView = (ListView)findViewById(R.id.listview);

//        ((AdapterView<ListAdapter>) mListView).setAdapter(mAdapter);

        mListView.setAdapter(mAdapter);
        // Set OnItemClickListener so we can be notified on item clicks
        mListView.setOnItemClickListener(this);

        mListView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
            @Override
            public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
                new AlertDialog.Builder(RecommendDoctorActivity.this)
                        .setTitle("确认添加好友吗？")//应该还要显示选择的日期，
                        .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {

                            }
                        })
                        .setNegativeButton("取消", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {

                            }
                        })
                        .create()
                        .show();
                return false;
            }
        });

    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//        if (null != mListener) {
        // Notify the active callbacks interface (the activity, if the
        // fragment is attached to one) that an item has been selected.
//            mListener.onFragmentInteraction(DummyContent.ITEMS.get(position).id);
//        }
        //启动病例的详情页面
//        Intent intent = new Intent(this, HistoryInfoActivity.class);
//        intent.putExtra("textview1", lists.get(position).text1);
//        intent.putExtra("textview2",lists.get(position).text2);
//        intent.putExtra("textview3",lists.get(position).text3);
//        intent.putExtra("textview4", lists.get(position).text4);
//        startActivity(intent);
        Toast.makeText(this,"进去该医生的详细资料界面",Toast.LENGTH_LONG).show();
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_recommend_doctor, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}
